package net.liteheaven.xblib.common.rom;

import android.os.Build;

import java.lang.reflect.Method;

/**
 * 手机系统ROM帮助类
 * Created by liangy on 2017/1/11.
 */
public class RomHelper {

    public static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
    public static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
    public static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";

    public static boolean isFlyme() {
        try {
            // Invoke Build.hasSmartBar()
            final Method method = Build.class.getMethod("hasSmartBar");
            return method != null;
        } catch (final Exception e) {
            return false;
        }
    }

    public static boolean isMiui(){
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            String versionCode = prop.getProperty(KEY_MIUI_VERSION_CODE, null);
            String versionName = prop.getProperty(KEY_MIUI_VERSION_NAME, null);
            String internalStorage = prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null);
            return versionCode != null
                    || versionName != null
                    || internalStorage != null;
        } catch (Exception e) {
            return false;
        }
    }

    public static String getMiuiVersionName(){
        try {
            final BuildProperties prop = BuildProperties.newInstance();
            String versionName = prop.getProperty(KEY_MIUI_VERSION_NAME, null);
            return versionName;
        } catch (Exception e) {
            return null;
        }
    }
}
